package galaxy;

import irio.gamer.gamer;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import Logic.GalaxyComponent;

public class GalaxyComponentListPanel extends JPanel {

	public static DefaultListModel list = new DefaultListModel();

	public void reload() {
		list.clear();
		for (int i = 0; i<gamer.galaxy.components.size();i++) {
			list.addElement("Component " + (i+1) + " : " + GalaxyComponent.types[(int)gamer.galaxy.components.get(i).type.x]);
		}
		
	}
	JList lst = null;
	public GalaxyComponentListPanel() {
		list.clear();
		lst = new JList(list);
		setLayout(new BorderLayout());
		for (int i = 0; i<gamer.galaxy.components.size();i++) {
			list.addElement("Component " + (i+1) + " : " + GalaxyComponent.types[(int)gamer.galaxy.components.get(i).type.x]);
		}
		
		lst.addListSelectionListener(new ListSelectionListener() {
			
			public void valueChanged(ListSelectionEvent e) {
				if (e.getValueIsAdjusting() == false) {
			        if (lst.getSelectedIndex() != -1) {
			        	System.out.println(lst.getSelectedIndex());
			        	//GalaxyComponentPanel.cp.Set(gamer.galaxy.components.get(0));
			        	GalaxyComponentPanel.cp.Set(gamer.galaxy.components.get(lst.getSelectedIndex()));
			        	repaint();
			        }
			    }
			}
		});
		add(lst, BorderLayout.NORTH);
		add(GalaxyComponentPanel.buttonPanel(), BorderLayout.SOUTH);
	}
}
